package com.hujf.netty.inandoutboundhandler;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageCodec;
import io.netty.handler.codec.ByteToMessageDecoder;

import java.util.List;

/**
 * @author Hujf
 * @title: MyByteToLongDecoder
 * @date 2021/2/6 0006上午 9:21
 * @description: TODO
 */
public class MyByteToLongDecoder extends ByteToMessageDecoder {

    /**
     *
     * @param ctx 上下文
     * @param in  入栈的buf
     * @param out  存储的内容 给下一个handler
     * @throws Exception
     */
    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List out) throws Exception {
        System.out.println("输入端 解码被调用");
        //long 8字节
        if(in.readableBytes()>=8){
            out.add(in.readLong());
        }
    }
}
